package com.ruoyi.admin.service.impl;

import java.util.List;

import com.ruoyi.admin.domain.vo.RepairVo;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.admin.mapper.RepairMapper;
import com.ruoyi.admin.domain.Repair;
import com.ruoyi.admin.service.IRepairService;

/**
 * 实验室维修Service业务层处理
 * 
 * @author lin
 * @date 2024-04-20
 */
@Service
public class RepairServiceImpl implements IRepairService 
{
    @Autowired
    private RepairMapper repairMapper;

    /**
     * 查询实验室维修
     * 
     * @param repairId 实验室维修主键
     * @return 实验室维修
     */
    @Override
    public RepairVo selectRepairByRepairId(Long repairId)
    {
        return repairMapper.selectRepairByRepairId(repairId);
    }

    /**
     * 查询实验室维修列表
     * 
     * @param repair 实验室维修
     * @return 实验室维修
     */
    @Override
    public List<RepairVo> selectRepairList(Repair repair)
    {
        return repairMapper.selectRepairList(repair);
    }

    /**
     * 新增实验室维修
     * 
     * @param repair 实验室维修
     * @return 结果
     */
    @Override
    public int insertRepair(Repair repair)
    {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        System.out.println(user);
        repair.setTeacherId(user.getUserId());
        return repairMapper.insertRepair(repair);
    }

    /**
     * 修改实验室维修
     * 
     * @param repair 实验室维修
     * @return 结果
     */
    @Override
    public int updateRepair(Repair repair)
    {
        String status = repair.getStatus();
        if ("已维修".equals(status)){
            status="0";
        }else if ("未维修".equals(status)){
            status="1";
        }else if ("维修中".equals(status)){
            status="2";
        }
        repair.setStatus(status);
        return repairMapper.updateRepair(repair);
    }

    /**
     * 批量删除实验室维修
     * 
     * @param repairIds 需要删除的实验室维修主键
     * @return 结果
     */
    @Override
    public int deleteRepairByRepairIds(Long[] repairIds)
    {
        return repairMapper.deleteRepairByRepairIds(repairIds);
    }

    /**
     * 删除实验室维修信息
     * 
     * @param repairId 实验室维修主键
     * @return 结果
     */
    @Override
    public int deleteRepairByRepairId(Long repairId)
    {
        return repairMapper.deleteRepairByRepairId(repairId);
    }
}
